﻿using Hospital.IRepository;
using Hospital.Model;
using Hospital.Model.entity;
using SqlSugar;


namespace Hospital.Repository
{
    public class PatientRepository : BaseRepository<Patient>, IPatientRepository
    {
        public PatientRepository(ISqlSugarClient db) : base(db)
        {
        }
        public override async Task<List<dynamic>> QueryAsyncDynamic()
        {
            // 定义 SQL 查询语句
            string sql = @"
        SELECT 
            Patient.*, 
            Department.Name AS DepartmentName 
        FROM 
            Patient 
        LEFT JOIN 
            Department ON Patient.DepartmentID = Department.DepartmentID;";

            // 使用 SqlSugar 的异步方法执行查询
            var result = await db.Ado.SqlQueryAsync<dynamic>(sql);
            // 返回查询结果
            return result;
        }
        public async override Task<List<Patient>> QueryAsync()
        {
            return await base.Context.Queryable<Patient>()
                //参数1 子表 ，参数2 外键1 ，参数3 外键2
                .ToListAsync();
        }
    }
}
